package com.lmx.repoDomain.tmodel;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.google.common.collect.Sets;
import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 评价结果
 *
 * @author ytche
 * @date 2017年7月21日
 *
 */
@JsonApiResource(type = "appraiseResult")
@Entity
@Table(name = "tnb_appraise_result")
public class AppraiseResult extends BaseEntity {
	private static final long serialVersionUID = 1L;
	private User appraiseUser;
	private Customer appraiseCustomer;
	private Integer appraiseTime;
	private Appraise appraise;
	private Set<AppraiseResultItem> items = Sets.newHashSet();
	private Employee employee;

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "user_id")
	public User getAppraiseUser() {
		return appraiseUser;
	}

	public void setAppraiseUser(User appraiseUser) {
		this.appraiseUser = appraiseUser;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "customer_id")
	public Customer getAppraiseCustomer() {
		return appraiseCustomer;
	}

	public void setAppraiseCustomer(Customer appraiseCustomer) {
		this.appraiseCustomer = appraiseCustomer;
	}

	@Column(name = "apraise_time")
	public Integer getAppraiseTime() {
		return appraiseTime;
	}

	public void setAppraiseTime(Integer appraiseTime) {
		this.appraiseTime = appraiseTime;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JsonApiToOne
	@JsonApiIncludeByDefault
	@JoinColumn(name = "appraise_id")
	public Appraise getAppraise() {
		return appraise;
	}

	public void setAppraise(Appraise appraise) {
		this.appraise = appraise;
	}

	@JsonApiToMany
	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH, mappedBy = "result")
	@Fetch(FetchMode.JOIN)
	public Set<AppraiseResultItem> getItems() {
		return items;
	}

	public void setItems(Set<AppraiseResultItem> items) {
		this.items = items;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "employee_id")
	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
}
